//
//  MoviexxxxxxViewController.m
//  UI20_豆瓣电影storyBoard
//
//  Created by 王阳阳 on 16/1/4.
//  Copyright © 2016年 www.lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "MoviexxxxxxViewController.h"
#import "NetWorkHandler.h"
#import "UIImageView+WebCache.h"
#import "DataBaseManager.h"
#import "movie.h"
@interface MoviexxxxxxViewController ()

@end

@implementation MoviexxxxxxViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self.image sd_setImageWithURL:[NSURL URLWithString:self.m.pic_url]];
    self.navigationItem.title = self.m.movieName;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"btn_nav_share"] style:UIBarButtonItemStylePlain target:self action:@selector(right)];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];

    
    
}
- (void)right
{
    
   
    
    DataBaseManager *dbManger = [DataBaseManager shareInstance];
    
    [dbManger openDB];
 
    [[DataBaseManager shareInstance] createTable];

    
    
    movie *m = [[movie alloc]init];
    m.movieName = self.m.movieName;
   NSMutableArray *arr1 = [[DataBaseManager shareInstance] selectMovie];
    
        for (movie *sm in arr1) {
        if ([sm.movieName isEqualToString: m.movieName]) {
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"已经收藏" preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alertController animated:YES completion:nil];
            [self performSelector:@selector(diss:) withObject:@"ssss" afterDelay:2];
            return;

        }
    }
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alertController animated:YES completion:nil];
    [self performSelector:@selector(diss:) withObject:@"ssss" afterDelay:2];

    [[DataBaseManager shareInstance]insertMovie:m];
    
}

- (void)diss:(id)a
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
